package lianxi01;

import java.util.Scanner;

public class LianXi6 {
    public static void main(String[] args) {
        //循环录入某学生5门课的成绩并计算平均分，
        //如果某分数录入为负，停止录入并提示错误
        int num = 0;
        int nums = 0;
        boolean flag = true;
        for (int i=0;i<5;i++){
            System.out.println("请输入你的第"+(i+1)+"门课的成绩:");
            Scanner scanner = new Scanner(System.in);
            num = scanner.nextInt();
            if (num<0){
                System.out.println("你的输入有误，请重新输入");
                flag = false;
                break;
            }
            System.out.println("第"+(i+1)+"课成绩为："+num);
            nums = nums+num;
        }
        if (flag){
            System.out.println("总分为："+nums);
            System.out.println("平均分为："+nums/5);
        }
    }
}
